import 'package:flutter/material.dart';

class AppBarExample02 extends StatefulWidget {
  @override
  _AppBarExample01State createState() => _AppBarExample01State();
}

class _AppBarExample01State extends State<AppBarExample02>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  List<Tab> tabs = [];

  @override
  void initState() {
    tabs = <Tab>[
      Tab(text: "Tab1"),
      Tab(text: "Tab2"),
      Tab(text: "Tab3"),
      Tab(text: "Tab4"),
      Tab(text: "Tab5"),
      Tab(text: "Tab6"),
      Tab(text: "Tab7"),
      Tab(text: "Tab8"),
      Tab(
        text: "Tab9",
        icon: Icon(Icons.phone),
      )
    ];

    _tabController =
        TabController(initialIndex: 2, length: tabs.length, vsync: this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("AppBarExample02"),
        bottom: TabBar(
          tabs: tabs,
          controller: _tabController,
          isScrollable: true,
        ),
      ),
      body: TabBarView(
        children: tabs
            .map((Tab tab) => Container(
                  child: Center(
                    child: Text(tab.text),
                  ),
                ))
            .toList(),
        controller: _tabController,
      ),
    );
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }
}
